<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"
    />
  </head>
  <body>
    <div class="container">
      <h1 class="mt-5 mb-5">文章列表</h1>

      <ul class="pagination">
        <li class="page-item <%= pageNum === 1 ? 'disabled' : '' %>">
          <a
            class="page-link"
            href="/posts?pageNum=<%= pageNum === 1 ? 1 : pageNum - 1 %>"
            >Prev</a
          >
        </li>

        <% for (var i = 1; i <= totalPages; i++) { %>
        <li class="page-item <%= pageNum === i ? 'active' : '' %>">
          <a class="page-link" href="/posts?pageNum=<%= i %>"><%= i %></a>
        </li>
        <% } %>

        <li class="page-item <%= pageNum === totalPages ? 'disabled' : '' %>">
          <a
            class="page-link"
            href="/posts?pageNum=<%= pageNum === totalPages ? totalPages : pageNum + 1 %>"
            >Next</a
          >
        </li>
      </ul>

      <ul class="list-group">
        <% for (var i = 0; i < posts.length; i++) { %>
        <li class="list-group-item">
          <h2>
            <a href="/posts/<%= posts[i]._id %>"><%= posts[i].title %></a>
          </h2>
          <p><%= posts[i].body %></p>
        </li>
        <% } %>
      </ul>
    </div>
  </body>
</html>
